/**
 * @file class.js
 * @description 班级管理API接口
 * @created 2024-05-10
 */

import request from '@/utils/request'

/**
 * 获取班级列表
 * @param {Object} params - 查询参数
 * @returns {Promise} 班级列表
 */
export function getClassList(params) {
  return request({
    url: '/api/admin/classes',
    method: 'get',
    params
  })
}

/**
 * 获取班级详情
 * @param {string} classId - 班级ID
 * @returns {Promise} 班级详情
 */
export function getClassDetail(classId) {
  return request({
    url: `/api/admin/classes/${classId}`,
    method: 'get'
  })
}

/**
 * 获取班级学生列表
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @returns {Promise} 学生列表
 */
export function getClassStudents(teacherId, courseId, classId) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/students`,
    method: 'get'
  })
}

/**
 * 获取班级课程统计信息
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @returns {Promise} 班级课程统计信息
 */
export function getClassCourseStats(teacherId, courseId, classId) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/stats`,
    method: 'get'
  })
}

/**
 * 更新学生成绩
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @param {string} studentId - 学生ID
 * @param {Object} data - 成绩信息
 * @returns {Promise} 更新结果
 */
export function updateStudentScore(teacherId, courseId, classId, studentId, data) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/students/${studentId}/score`,
    method: 'put',
    data
  })
}

/**
 * 获取班级学生成绩详情
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @returns {Promise} 班级学生成绩详情
 */
export function getClassStudentsScores(teacherId, courseId, classId) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/students/`,
    method: 'get'
  })
}

/**
 * 获取班级成绩分布统计
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @returns {Promise} 班级成绩分布统计
 */
export function getClassScoreDistribution(teacherId, courseId, classId) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/score-distribution`,
    method: 'get'
  })
}

/**
 * 获取班级学生成绩分布详情
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @returns {Promise} 成绩分布详情数据
 */
export function getClassScoreDetails(teacherId, courseId, classId) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/score-details`,
    method: 'get'
  })
}

/**
 * 导出班级学生成绩表
 * @param {string} teacherId - 教师ID
 * @param {string} courseId - 课程ID
 * @param {string} classId - 班级ID
 * @returns {Promise} 导出结果
 */
export function exportClassScores(teacherId, courseId, classId) {
  return request({
    url: `/api/admin/teachers/${teacherId}/courses/${courseId}/classes/${classId}/export-scores`,
    method: 'get',
    responseType: 'blob'
  })
} 